using System;
using System.Collections;
using System.Collections.Generic;
using Protocols;
using UnityEngine;
using UnityEngine.AI;

[RequireComponent(typeof(NavMeshAgent), typeof(Animator))]
public class OtherPlayer : MonoBehaviour
{
    private NavMeshAgent agent;
    private Animator animation;

    private void Awake()
    {
        agent = GetComponent<NavMeshAgent>();
        animation = GetComponent<Animator>();
    }

    private MoveData? oldData = null;
    public void Move(MoveData data)
    {
        var first = oldData == null;
        if (oldData != null && oldData.Value.Compare(data))
        {
            return;
        }

        oldData = data;
        animation.SetBool("walk", data.move);
        animation.SetInteger("dir", data.dir);

        if (data.move)
        {
            agent.SetDestination(new Vector3(data.pos_x, data.pos_y, data.pos_z));
        }
    }
}
